package repository

import (
	"context"
	"octopus/hextech/server"
	"octopus/user/infra/acl/convert"
	"octopus/user/model/domain/user"

	"github.com/go-redis/redis/v7"
	"gorm.io/gorm"
)

type UserRepoImpl struct {
	db  *gorm.DB
	rds *redis.Client
	ctx context.Context
}

func NewUserRepoImpl(ctx context.Context) user.Repository {
	u := new(UserRepoImpl)
	u.db = server.APP.GetDB()
	u.rds = server.APP.GetRedis()
	u.ctx = ctx
	return u
}

func (u UserRepoImpl) DB() *gorm.DB {
	return u.db
}

func (u UserRepoImpl) Create(user *user.User) error {
	cp := convert.UserDomain2Po(user)
	res := u.db.Table(cp.TableName()).Save(&cp)
	if res.Error != nil {
		return res.Error
	}
	return nil
}

func (u UserRepoImpl) Save(user *user.User) error {
	//TODO implement me
	panic("implement me")
}

func (u UserRepoImpl) Delete(userID int64) error {
	//TODO implement me
	panic("implement me")
}

func (u UserRepoImpl) Login(user *user.User) error {
	//TODO implement me
	panic("implement me")
}
